<template>
  <div>
    <h1>aa</h1>
    <p>{{ msg }}</p>
    <button @click="msg = 'hello'">修改msg</button> <br />
  </div>
</template>

<script>
export default {
  name: "VueDemoDemo",

  data() {
    return {
      msg: "你好世界",
    };
  },
  // 初始化阶段
  beforeCreate() {
    // 组件加载前的钩子
    console.log("beforeCreate", this.msg);
  },
  created() {
    // 发送 ajax 在这里面
    console.log("created", this.msg);
  },
  beforeMount() {
    // 页面加载前的钩子
    const p = document.querySelector("p");
    console.log("beforeMount", p);
  },
  mounted() {
    const p = document.querySelector("p");
    console.log("mounted", p);
  },
  // 运行阶段
  beforeUpdate() {
    // DOM 重新渲染之前的钩子
    const p = document.querySelector("p");
    console.log("beforeUpdate", p.innerHTML);
  },
  updated() {
    const p = document.querySelector("p");
    console.log("updated", p.innerHTML);
  },
  //销毁阶段
  beforeDestroy() {
    // 组件销毁之前
    const p = document.querySelector("p");
    console.log("beforeDestroy", p);
  },
  destroyed() {
    const p = document.querySelector("p");
    console.log("destroyed", p);
  },
};
</script>

<style lang="scss" scoped>
</style>